package com.waves.spring.bean;

import com.waves.task.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Slf4j
@Component
public class TestBean implements BeanNameAware, BeanFactoryAware, ApplicationContextAware {

    public TestBean() {
        log.info(">>>②实例化中 执行构造方法");
    }


    @Autowired
    public void autowire(TaskService taskService) {
        log.info(">>>⑤正在依赖注入属性中: {}", taskService);
    }

    @PostConstruct
    public void init() {
        log.info(">>>⑩正在初始化中");
    }

    @PreDestroy
    public void destroy() {
        log.info(">>>①③正在销毁中");
    }

    @Override
    public void setBeanName(String s) {
        log.info(">>>⑥BeanNameAware回调 bean名称是:{}",s);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        log.info(">>>⑦BeanFactoryAware回调 beanFactory容器是: {}",beanFactory);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        log.info(">>>⑧ApplicationContextAware回调 applicationContext容器是:{}",applicationContext);
    }


}
